package sort.provider;

import anaydis.sort.Sorter;
import anaydis.sort.SorterType;
import anaydis.sort.provider.SorterProvider;
import sort.impl.*;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

public class SorterProviderImpl implements SorterProvider{
    private Map<SorterType, Sorter> map;

    public SorterProviderImpl(){
        map = new EnumMap<SorterType, Sorter>(SorterType.class);
        map.put(SorterType.BUBBLE, new BubbleSorter());
        map.put(SorterType.SELECTION, new SelectionSorter());
        map.put(SorterType.INSERTION, new InsertionSorter());
        map.put(SorterType.SHELL, new ShellSorter(initFirstSequence()));
        map.put(SorterType.H, new HSorter());
        map.put(SorterType.QUICK, new QuickSorter());
        map.put(SorterType.QUICK_CUT, new QuickSorterCutOff());
        map.put(SorterType.MERGE, new MergeSortTopDown());
        map.put(SorterType.MERGE_BOTTOM_UP, new MergeSortBottomUp());
    }

    private static List<Integer> initFirstSequence() {
        List<Integer> firstSequence = new ArrayList<Integer>();
        firstSequence.add(1657);
        firstSequence.add(4193);
        firstSequence.add(1073);
        firstSequence.add(281);
        firstSequence.add(77);
        firstSequence.add(23);
        firstSequence.add(8);
        return firstSequence;
    }

    @NotNull
    public Sorter getSorterForType(@NotNull SorterType sorterType) {
        return map.get(sorterType);
    }

    @NotNull
    public Iterable<Sorter> getAllSorters() {
        return map.values();        
    }
}
